﻿using _1._12._2015_TodoWebAPI.Data;
using _1._12._2015_TodoWebAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace _1._12._2015_TodoWebAPI.Adapters
{
    public class TodoDataAdapter : ITodoAdapter
    {
        public List<TodoViewModel> GetTodos(string userId)
        {
            List<TodoViewModel> models = null;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                models = db.Todos.Where(t => t.UserId == userId).Select(t => new TodoViewModel
                {
                    Id = t.TodoId,
                    City = t.City,
                    DateCreated = t.DateCreated,
                    IsCompleted = t.IsCompleted,
                    Text = t.Text,
                    User = t.User.UserName
                }).ToList();
            }

            return models;
        }
    }
}